package BFS;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-07
 * Time:16:51
 * Text：733. 图像渲染
 */
public class Text1 {
    int[] dx={0,0,1,-1};
    int[] dy={1,-1,0,0};
    public int[][] floodFill(int[][] image, int sr, int sc, int color) {
        int prve=image[sr][sc];
        if(prve == color) return image;
        Queue<int[]> q=new LinkedList<>();
        q.add(new int[]{sr,sc});
        while(!q.isEmpty()){
            int[] t=q.poll();
            int x=t[0],y=t[1];
            image[x][y]=color;
            for(int i = 0 ; i < 4; i++){
                int x1=x+dx[i],y1=y+dy[i];
                if(x1>=0 && x1<image.length && y1>=0 && y1<image[0].length && image[x1][y1]==prve){
                    q.add(new int[]{x1,y1});
                }
            }
        }
        return image;
    }
    public static void main(String[] args) {

    }
}
